<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>仪表盘 - 多用户报警系统</title>
    {% load static %}
    <link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
    <link rel="stylesheet" href="{% static 'font-awesome/css/font-awesome.min.css' %}">
    <style>
        /* 基础样式 */
        body {
            background-color: #f8f9fa;
            color: #212529;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
        }
        
        /* 导航栏样式 */
        .navbar {
            background-color: #ffffff;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        .navbar-brand {
            font-weight: bold;
            color: #1677ff;
            font-size: 1.25rem;
        }
        
        .navbar-brand:hover {
            color: #0958d9;
        }
        
        .nav-link {
            color: #212529;
            transition: color 0.2s;
        }
        
        .nav-link:hover {
            color: #1677ff;
        }
        
        /* 主容器样式 */
        .main-container {
            min-height: calc(100vh - 100px);
            padding-top: 20px;
            padding-bottom: 20px;
        }
        
        /* 卡片样式 */
        .card {
            border: none;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
            transition: transform 0.2s, box-shadow 0.2s;
            margin-bottom: 20px;
        }
        
        .card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
        }
        
        .card-header {
            background-color: #ffffff;
            border-bottom: 1px solid #f0f0f0;
            font-weight: bold;
            color: #212529;
        }
        
        /* 按钮样式 */
        .btn {
            border-radius: 6px;
            font-weight: 500;
            transition: all 0.2s;
        }
        
        /* 表格样式 */
        .table {
            border-collapse: separate;
            border-spacing: 0;
        }
        
        .table thead th {
            background-color: #fafafa;
            font-weight: 600;
            color: #212529;
            border-bottom: 2px solid #f0f0f0;
        }
        
        .table tbody tr {
            transition: background-color 0.2s;
        }
        
        .table tbody tr:hover {
            background-color: #fafafa;
        }
        
        /* 消息提示样式 */
        .alert {
            border-radius: 6px;
            border: none;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        }
        
        /* 页脚样式 */
        footer {
            background-color: #ffffff;
            color: #6c757d;
            padding: 20px 0;
            border-top: 1px solid #f0f0f0;
            margin-top: 40px;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg sticky-top">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">
                <i class="fa fa-bell-o" aria-hidden="true"></i> 多用户报警系统
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                {% if user.is_authenticated %}
                    <ul class="navbar-nav me-auto">
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'projects:dashboard' %}">
                        <i class="fa fa-home" aria-hidden="true"></i> 首页
                    </a>
                        </li>
                        {% if user.is_super_admin %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'accounts:user_list' %}">
                                <i class="fa fa-users" aria-hidden="true"></i> 用户管理
                            </a>
                        </li>
                        {% endif %}
                    </ul>
                    <ul class="navbar-nav">
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="fa fa-user-circle-o" aria-hidden="true"></i> {{ user.username }}
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
                                <!-- dashboard路径已隐藏 -->
                                <li><hr class="dropdown-divider"></li>
                                <li><a class="dropdown-item" href="{% url 'accounts:logout' %}"><i class="fa fa-sign-out" aria-hidden="true"></i> 退出登录</a></li>
                            </ul>
                        </li>
                    </ul>
                {% else %}
                    <ul class="navbar-nav ms-auto">
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'accounts:login' %}">
                                <i class="fa fa-sign-in" aria-hidden="true"></i> 登录
                            </a>
                        </li>
                    </ul>
                {% endif %}
            </div>
        </div>
    </nav>

    <!-- 主内容区域 -->
    <div class="container main-container">
        <!-- 消息提示 -->
        {% if messages %}
            {% for message in messages %}
                <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                    <i class="fa fa-info-circle" aria-hidden="true"></i> {{ message }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            {% endfor %}
        {% endif %}

        <div class="mb-4">
            <h1 class="mb-4">
                <i class="fa fa-dashboard" aria-hidden="true"></i> 仪表盘
            </h1>
            
            <div class="row">
                <!-- 欢迎卡片 -->
                <div class="col-md-6">
                    <div class="card">
                        <div class="card-header">
                            <h2 class="h4">欢迎回来，{{ user.username }}！</h2>
                        </div>
                        <div class="card-body">
                            <p class="mb-0">您上次登录时间：{{ user.last_login|date:"Y年m月d日 H:i:s" }}</p>
                            {% if user.phone %}
                                <p class="mb-0">您的手机号：{{ user.phone }}</p>
                            {% endif %}
                            {% if user.email %}
                                <p class="mb-0">您的邮箱：{{ user.email }}</p>
                            {% endif %}
                            <div class="mt-3">
                                <a href="{% url 'accounts:profile_edit' %}" class="btn btn-primary btn-sm">
                                    <i class="fa fa-pencil" aria-hidden="true"></i> 编辑个人资料
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 用户统计卡片 -->
                <div class="col-md-6">
                    <div class="card">
                        <div class="card-header">
                            <h2 class="h4">我的项目统计</h2>
                        </div>
                        <div class="card-body">
                            <div class="row text-center">
                                <div class="col-6">
                                    <div class="p-3 rounded-lg bg-primary bg-opacity-10">
                                        <i class="fa fa-folder-open-o" aria-hidden="true" style="font-size: 2rem; color: #1677ff;"></i>
                                        <h3 class="h2 mt-2">{{ user_projects.count }}</h3>
                                        <p class="text-muted">参与项目</p>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="p-3 rounded-lg bg-success bg-opacity-10">
                                        <i class="fa fa-user-circle-o" aria-hidden="true" style="font-size: 2rem; color: #52c41a;"></i>
                                        <h3 class="h2 mt-2">{{ user_created_projects.count }}</h3>
                                        <p class="text-muted">创建项目</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Webhook消息清单 -->
            <div class="card">
                <div class="card-header">
                    <h2 class="h4 mb-0">
                        <i class="fa fa-envelope-o" aria-hidden="true"></i> Webhook消息清单
                    </h2>
                </div>
                <div class="card-body">
                    {% if webhook_messages %}
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>时间</th>
                                        <th>标题</th>
                                        <th>所属项目</th>
                                        <th>来源</th>
                                        <th>IP地址</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for message in webhook_messages %}
                                        <tr>
                                            <td>{{ message.timestamp|slice:':19' }}</td>
                                            <td>
                                                {% if message.data %}
                                                    {% if message.data.title %}
                                                        {{ message.data.title|truncatechars:50 }}
                                                    {% elif message.data.message %}
                                                        {{ message.data.message|truncatechars:50 }}
                                                    {% elif message.data.test %}
                                                        {{ message.data.test|truncatechars:50 }}
                                                    {% elif message.data.event %}
                                                        {{ message.data.event|truncatechars:50 }}
                                                    {% else %}
                                                        {{ message.data|stringformat:'s'|truncatechars:50 }}
                                                    {% endif %}
                                                {% else %}
                                                    无内容
                                                {% endif %}
                                            </td>
                                            <td><a href="{% url 'projects:project_detail' message.project.id %}">{{ message.project.name }}</a></td>
                                            <td>{{ message.source|truncatechars:30 }}</td>
                                            <td>{{ message.ip }}</td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    {% else %}
                        <p class="text-center text-muted">暂无Webhook消息数据</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    </div>
    
    <!-- 页脚 -->
    <footer>
        <div class="container text-center">
            <p>&copy; {% now 'Y' %} 多用户报警系统 | 技术支持：Python + Django</p>
        </div>
    </footer>

    <script src="{% static 'bootstrap/js/bootstrap.bundle.min.js' %}"></script>
    <script>
        // 添加页面加载动画效果
        document.addEventListener('DOMContentLoaded', function() {
            // 为卡片添加悬停效果
            const cards = document.querySelectorAll('.card');
            cards.forEach(card => {
                card.addEventListener('mouseenter', function() {
                    this.style.transform = 'translateY(-2px)';
                    this.style.boxShadow = '0 4px 16px rgba(0, 0, 0, 0.12)';
                });
                card.addEventListener('mouseleave', function() {
                    this.style.transform = 'translateY(0)';
                    this.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.08)';
                });
            });
        });
    </script>
</body>
</html>